package com.cll.mapper;

import com.cll.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    /**
     * 根据条件来查询购物车的记录
     * @param shoppingCart
     * @return
     */
    ShoppingCart find(ShoppingCart shoppingCart);

    /**
     * 更改购物车数据
     * @param dbShoppingCart
     */
    void updateCount(ShoppingCart dbShoppingCart);

    /**
     * 添加进购物车
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart value (null,#{name},#{image},#{userId},#{dishId},#{setmealId},\n" +
            "#{dishFlavor},#{number},#{amount},#{createTime})")
    void save(ShoppingCart shoppingCart);

    /**
     * 查询获取购物车里所有集合
     * @param userId
     * @return
     */
    @Select("select * from shopping_cart where user_id = #{userId} order by create_time asc")
    List<ShoppingCart> list(Long userId);


    /**
     *清空购物车
     * @param userId
     */
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void clean(Long userId);


    /**
     * 删除购物车中一个商品 根据id来删除物品
     * @param id
     */
    @Delete("delete from shopping_cart where id = #{id}")
    void deleteById(Long id);

    /**
     * 删除购物车中一个商品
     * @param dbShoppingCart
     */
    @Delete("delete from shopping_cart where id = #{id}")
    void deleteCount(ShoppingCart dbShoppingCart);

    /**
     * 用户再来一单
     * @param shoppingCartList
     */
    void inserBatch(List<ShoppingCart> shoppingCartList);
}